package shop.controls;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import shop.pojo.Brand;
import shop.services.BrandServices;

/**
 * Servlet implementation class BrandUptBrand
 */
public class BrandUptBrand extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public BrandUptBrand() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		this.doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String strB_id = request.getParameter("b_id");
		String b_name = request.getParameter("b_name");
		Brand brand = new Brand();
		brand.setB_id(Integer.parseInt(strB_id));
		brand.setB_name(b_name);
		int i = new BrandServices().uptOneBrand(brand);
		if(i>0){
			request.getRequestDispatcher("BrandSel.do").forward(request, response);
		}else{
			request.getRequestDispatcher("BrandUpt.do?b_id="+Integer.parseInt(strB_id)).forward(request, response);
		}
	}

}
